//   Copyright 2012,2013 Vaughn Vernon
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package com.saasovation.common.notification;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 通知日志
 * @author learn
 */
public class NotificationLog {
    /**
     * 是否已存档
     */
    private boolean archived;
    /**
     * 通知清单
     */
    private List<Notification> notifications;
    /**
     * 通知日志ID
     */
    private String notificationLogId;
    /**
     * 下一个通知日志ID
     */
    private String nextNotificationLogId;
    /**
     * 上一个通知日志ID
     */
    private String previousNotificationLogId;

    /**
     * 由以下参数构造通知日志
     * @param aNotificationLogId            通知日志ID
     * @param aNextNotificationLogId        下一个通知日志ID
     * @param aPreviousNotificationLogId    上一个通知日志ID
     * @param aNotifications                通知清单
     * @param anArchivedIndicator           是否已存档
     */
    public NotificationLog(
            String aNotificationLogId,
            String aNextNotificationLogId,
            String aPreviousNotificationLogId,
            List<Notification> aNotifications,
            boolean anArchivedIndicator) {

        super();

        this.setArchived(anArchivedIndicator);
        this.setNextNotificationLogId(aNextNotificationLogId);
        this.setNotificationLogId(aNotificationLogId);
        this.setNotifications(aNotifications);
        this.setPreviousNotificationLogId(aPreviousNotificationLogId);
    }

    /**
     * 获取是否已存档
     * @return                                  返回布尔
     */
    public boolean isArchived() {
        return this.archived;
    }

    /**
     * 获取通知清单
     * @return                                  返回列表
     */
    public List<Notification> notifications() {
        return Collections.unmodifiableList(this.notifications);
    }

    /**
     * 获取解码的通知日志ID
     * @return                                  返回通知日志ID
     */
    public NotificationLogId decodedNotificationLogId() {
        return new NotificationLogId(this.notificationLogId());
    }

    /**
     * 获取通知日志ID
     * @return                                  返回字符串
     */
    public String notificationLogId() {
        return this.notificationLogId;
    }

    /**
     * 解码的下一个通知日志ID
     * @return                                  返回通知日志ID
     */
    public NotificationLogId decodedNextNotificationLogId() {
        return new NotificationLogId(this.nextNotificationLogId());
    }

    /**
     * 下一个通知日志ID
     * @return                                  返回字符串
     */
    public String nextNotificationLogId() {
        return this.nextNotificationLogId;
    }

    /**
     * 是否有下一个通知日志
     * @return                                  返回布尔
     */
    public boolean hasNextNotificationLog() {
        return this.nextNotificationLogId() != null;
    }

    /**
     * 解码的上一个通知日志ID
     * @return                                  返回通知日志ID
     */
    public NotificationLogId decodedPreviousNotificationLogId() {
        return new NotificationLogId(this.previousNotificationLogId());
    }

    /**
     * 获取上一个通知日志ID
     * @return                                  返回字符串
     */
    public String previousNotificationLogId() {
        return this.previousNotificationLogId;
    }

    /**
     * 是否有上一个通知日志
     * @return                                  返回布尔
     */
    public boolean hasPreviousNotificationLog() {
        return this.previousNotificationLogId() != null;
    }

    /**
     * 通知清单的大小
     * @return                                  返回整型
     */
    public int totalNotifications() {
        return this.notifications.size();
    }

    /**
     * 通知日志
     */
    protected NotificationLog() {
        super();
        // 通知清单初始化
        this.setNotifications(new ArrayList<Notification>());
    }

    /**
     * 设置通知清单
     * @param aNotifications                    通知清单
     */
    private void setNotifications(List<Notification> aNotifications) {
        this.notifications = aNotifications;
    }

    /**
     * 设置通知日志ID
     * @param aNotificationLogId                通知日志ID
     */
    private void setNotificationLogId(String aNotificationLogId) {
        this.notificationLogId = aNotificationLogId;
    }

    /**
     * 设置下一个通知日志ID
     * @param aNextNotificationLogId            下一个通知日志ID
     */
    private void setNextNotificationLogId(String aNextNotificationLogId) {
        this.nextNotificationLogId = aNextNotificationLogId;
    }

    /**
     * 设置上一个通知日志ID
     * @param aPreviousNotificationLogId        上一个通知日志ID
     */
    private void setPreviousNotificationLogId(String aPreviousNotificationLogId) {
        this.previousNotificationLogId = aPreviousNotificationLogId;
    }

    /**
     * 设置已存档
     * @param aArchived                         已存档
     */
    private void setArchived(boolean aArchived) {
        this.archived = aArchived;
    }
}
